

on action theObject
	
	
	
	set numObra to contents of text field "procuraObras" of window "Prepress Ver Obras"
	set contents of text field "nObra" of window "Prepress Ver Obras" to numObra
	my sacarItensdaBasedeDados("nomeCliente", "Prepress Ver Obras", numObra, "nomeCliente", "prepress")
	my sacarItensdaBasedeDados("trabalho", "Prepress Ver Obras", numObra, "trabalho", "prepress")
	my sacarItensdaBasedeDados("quantidade", "Prepress Ver Obras", numObra, "quantidade", "prepress")
	my sacarItensdaBasedeDados("dataEntrada", "Prepress Ver Obras", numObra, "dataEntrada", "prepress")
	my sacarItensdaBasedeDados("formatoAberto", "Prepress Ver Obras", numObra, "formatoAberto", "prepress")
	my sacarItensdaBasedeDados("formatoFechado", "Prepress Ver Obras", numObra, "formatoFechado", "prepress")
	my sacarItensdaBasedeDados("dataPrevistaSaida", "Prepress Ver Obras", numObra, "dataPrevistaSaida", "prepress")
	my verificarEstadoDoTrabalho("trabalhoFinalizado", "Prepress Ver Obras", numObra, "trabalhoFinalizado", "prepress")
	
	-- Tab Prepress
	
	my sacarItensdaBasedeDadosTabView("tipoTrabalho", "prepress", "tabObras", "Prepress Ver Obras", numObra, "tipoTrabalho", "prepress")
	my sacarItensdaBasedeDadosTabView("obraAnterior", "prepress", "tabObras", "Prepress Ver Obras", numObra, "obraAnterior", "prepress")
	my sacarItensdaBasedeDadosTabView("planoImposicao", "prepress", "tabObras", "Prepress Ver Obras", numObra, "planoImposicao", "prepress")
	my sacarItensdaBasedeDadosTabView("operador", "prepress", "tabObras", "Prepress Ver Obras", numObra, "operador", "prepress")
	my sacarItensdaBasedeDadosTabView("a4", "prepress", "tabObras", "Prepress Ver Obras", numObra, "a4", "prepress")
	my sacarItensdaBasedeDadosTabView("a3", "prepress", "tabObras", "Prepress Ver Obras", numObra, "a3", "prepress")
	my sacarItensdaBasedeDadosTabView("scan", "prepress", "tabObras", "Prepress Ver Obras", numObra, "scan", "prepress")
	my sacarItensdaBasedeDadosTabView("clienteFornecePopUpTextField", "prepress", "tabObras", "Prepress Ver Obras", numObra, "clienteFornece, clienteForneceOutros", "prepress")
	
	-- Tab Obras
	
	my sacarItensdaBasedeDadosTabView("env1dia", "provas", "tabObras", "Prepress Ver Obras", numObra, "enviadaDia", "prova1")
	my sacarItensdaBasedeDadosTabView("env1hora", "provas", "tabObras", "Prepress Ver Obras", numObra, "enviadaHora", "prova1")
	
	my sacarItensdaBasedeDadosTabView("env2dia", "provas", "tabObras", "Prepress Ver Obras", numObra, "enviadaDia", "prova2")
	my sacarItensdaBasedeDadosTabView("env2hora", "provas", "tabObras", "Prepress Ver Obras", numObra, "enviadaHora", "prova2")
	
	my sacarItensdaBasedeDadosTabView("env3dia", "provas", "tabObras", "Prepress Ver Obras", numObra, "enviadaDia", "prova3")
	my sacarItensdaBasedeDadosTabView("env3hora", "provas", "tabObras", "Prepress Ver Obras", numObra, "enviadaHora", "prova3")
	
	my sacarItensdaBasedeDadosTabView("env4dia", "provas", "tabObras", "Prepress Ver Obras", numObra, "enviadaDia", "prova4")
	my sacarItensdaBasedeDadosTabView("env4hora", "provas", "tabObras", "Prepress Ver Obras", numObra, "enviadaHora", "prova4")
	
	
	my sacarItensdaBasedeDadosTabView("rec1dia", "provas", "tabObras", "Prepress Ver Obras", numObra, "recebidaDia", "prova1")
	my sacarItensdaBasedeDadosTabView("rec1hora", "provas", "tabObras", "Prepress Ver Obras", numObra, "recebidaHora", "prova1")
	
	my sacarItensdaBasedeDadosTabView("rec2dia", "provas", "tabObras", "Prepress Ver Obras", numObra, "recebidaDia", "prova2")
	my sacarItensdaBasedeDadosTabView("rec2hora", "provas", "tabObras", "Prepress Ver Obras", numObra, "recebidaHora", "prova2")
	
	my sacarItensdaBasedeDadosTabView("rec3dia", "provas", "tabObras", "Prepress Ver Obras", numObra, "recebidaDia", "prova3")
	my sacarItensdaBasedeDadosTabView("rec3hora", "provas", "tabObras", "Prepress Ver Obras", numObra, "recebidaHora", "prova3")
	
	my sacarItensdaBasedeDadosTabView("rec4dia", "provas", "tabObras", "Prepress Ver Obras", numObra, "recebidaDia", "prova4")
	my sacarItensdaBasedeDadosTabView("rec4hora", "provas", "tabObras", "Prepress Ver Obras", numObra, "recebidaHora", "prova4")
	
	
	my queProvasForamEnviadas("pdf1", "provas", "tabObras", "PrePress Ver Obras", numObra, "pdf", "prova1")
	my queProvasForamEnviadas("ozalide1", "provas", "tabObras", "PrePress Ver Obras", numObra, "ozalide", "prova1")
	my queProvasForamEnviadas("laser1", "provas", "tabObras", "PrePress Ver Obras", numObra, "laser", "prova1")
	my queProvasForamEnviadas("pcor1", "provas", "tabObras", "PrePress Ver Obras", numObra, "pdecor", "prova1")
	
	my queProvasForamEnviadas("pdf2", "provas", "tabObras", "PrePress Ver Obras", numObra, "pdf", "prova2")
	my queProvasForamEnviadas("ozalide2", "provas", "tabObras", "PrePress Ver Obras", numObra, "ozalide", "prova2")
	my queProvasForamEnviadas("laser2", "provas", "tabObras", "PrePress Ver Obras", numObra, "laser", "prova2")
	my queProvasForamEnviadas("pcor2", "provas", "tabObras", "PrePress Ver Obras", numObra, "pdecor", "prova2")
	
	my queProvasForamEnviadas("pdf3", "provas", "tabObras", "PrePress Ver Obras", numObra, "pdf", "prova3")
	my queProvasForamEnviadas("ozalide3", "provas", "tabObras", "PrePress Ver Obras", numObra, "ozalide", "prova3")
	my queProvasForamEnviadas("laser3", "provas", "tabObras", "PrePress Ver Obras", numObra, "laser", "prova3")
	my queProvasForamEnviadas("pcor3", "provas", "tabObras", "PrePress Ver Obras", numObra, "pdecor", "prova3")
	
	my queProvasForamEnviadas("pdf4", "provas", "tabObras", "PrePress Ver Obras", numObra, "pdf", "prova4")
	my queProvasForamEnviadas("ozalide4", "provas", "tabObras", "PrePress Ver Obras", numObra, "ozalide", "prova4")
	my queProvasForamEnviadas("laser4", "provas", "tabObras", "PrePress Ver Obras", numObra, "laser", "prova4")
	my queProvasForamEnviadas("pcor4", "provas", "tabObras", "PrePress Ver Obras", numObra, "pdecor", "prova4")
	
	-- Tab Impressão
	my sacarItensdaBasedeDadosTabView("maqImpressaoInterna", "impressao", "tabObras", "Prepress Ver Obras", numObra, "maqImpressaoInterna", "prepress")
	my sacarItensdaBasedeDadosTabView("lineatura", "impressao", "tabObras", "Prepress Ver Obras", numObra, "lineatura", "prepress")
	my sacarItensdaBasedeDadosTabView("tipoPapel", "impressao", "tabObras", "Prepress Ver Obras", numObra, "tipoPapel", "prepress")
	my sacarItensdaBasedeDadosTabView("impressaoExterna", "impressao", "tabObras", "Prepress Ver Obras", numObra, "impressaoExterna", "prepress")
	my sacarItensdaBasedeDadosTabView("coresCapa", "impressao", "tabObras", "Prepress Ver Obras", numObra, "coresCapa", "prepress")
	my sacarItensdaBasedeDadosTabView("pantoneCapa", "impressao", "tabObras", "Prepress Ver Obras", numObra, "pantoneCapa", "prepress")
	my sacarItensdaBasedeDadosTabView("coresMiolo", "impressao", "tabObras", "Prepress Ver Obras", numObra, "coresMiolo", "prepress")
	my sacarItensdaBasedeDadosTabView("pantoneMiolo", "impressao", "tabObras", "Prepress Ver Obras", numObra, "pantoneMiolo", "prepress")
	my sacarItensdaBasedeDadosTabView("obsCriarObra", "impressao", "tabObras", "Prepress Ver Obras", numObra, "obsCriarObra", "prepress")
	
	
	-- Tab Outros
	my introduzirImagem()
	my sacarItensdaBasedeDadosTabView("nomeComercial", "outros", "tabObras", "Prepress Ver Obras", numObra, "nomeComercial", "prepress")
	
	
	
	
	set contents of text field "procuraObras" of window "Prepress Ver Obras" to ""
end action


on clicked theObject
	
	set numObra to contents of text field "procuraObras" of window "Prepress Ver Obras"
	set contents of text field "nObra" of window "Prepress Ver Obras" to numObra
	my sacarItensdaBasedeDados("nomeCliente", "Prepress Ver Obras", numObra, "nomeCliente", "prepress")
	my sacarItensdaBasedeDados("trabalho", "Prepress Ver Obras", numObra, "trabalho", "prepress")
	my sacarItensdaBasedeDados("quantidade", "Prepress Ver Obras", numObra, "quantidade", "prepress")
	my sacarItensdaBasedeDados("dataEntrada", "Prepress Ver Obras", numObra, "dataEntrada", "prepress")
	my sacarItensdaBasedeDados("formatoAberto", "Prepress Ver Obras", numObra, "formatoAberto", "prepress")
	my sacarItensdaBasedeDados("formatoFechado", "Prepress Ver Obras", numObra, "formatoFechado", "prepress")
	my sacarItensdaBasedeDados("dataPrevistaSaida", "Prepress Ver Obras", numObra, "dataPrevistaSaida", "prepress")
	my verificarEstadoDoTrabalho("trabalhoFinalizado", "Prepress Ver Obras", numObra, "trabalhoFinalizado", "prepress")
	
	-- Tab Prepress
	
	my sacarItensdaBasedeDadosTabView("tipoTrabalho", "prepress", "tabObras", "Prepress Ver Obras", numObra, "tipoTrabalho", "prepress")
	my sacarItensdaBasedeDadosTabView("obraAnterior", "prepress", "tabObras", "Prepress Ver Obras", numObra, "obraAnterior", "prepress")
	my sacarItensdaBasedeDadosTabView("planoImposicao", "prepress", "tabObras", "Prepress Ver Obras", numObra, "planoImposicao", "prepress")
	my sacarItensdaBasedeDadosTabView("operador", "prepress", "tabObras", "Prepress Ver Obras", numObra, "operador", "prepress")
	my sacarItensdaBasedeDadosTabView("a4", "prepress", "tabObras", "Prepress Ver Obras", numObra, "a4", "prepress")
	my sacarItensdaBasedeDadosTabView("a3", "prepress", "tabObras", "Prepress Ver Obras", numObra, "a3", "prepress")
	my sacarItensdaBasedeDadosTabView("scan", "prepress", "tabObras", "Prepress Ver Obras", numObra, "scan", "prepress")
	my sacarItensdaBasedeDadosTabView("clienteFornecePopUpTextField", "prepress", "tabObras", "Prepress Ver Obras", numObra, "clienteFornece, clienteForneceOutros", "prepress")
	my sacarItensdaBasedeDadosTabView("env1dia", "provas", "tabObras", "Prepress Ver Obras", numObra, "enviadaDia", "prova1")
	my sacarItensdaBasedeDadosTabView("env1hora", "provas", "tabObras", "Prepress Ver Obras", numObra, "enviadaHora", "prova1")
	
	--TAb Provas
	my sacarItensdaBasedeDadosTabView("env2dia", "provas", "tabObras", "Prepress Ver Obras", numObra, "enviadaDia", "prova2")
	my sacarItensdaBasedeDadosTabView("env2hora", "provas", "tabObras", "Prepress Ver Obras", numObra, "enviadaHora", "prova2")
	
	my sacarItensdaBasedeDadosTabView("env3dia", "provas", "tabObras", "Prepress Ver Obras", numObra, "enviadaDia", "prova3")
	my sacarItensdaBasedeDadosTabView("env3hora", "provas", "tabObras", "Prepress Ver Obras", numObra, "enviadaHora", "prova3")
	
	my sacarItensdaBasedeDadosTabView("env4dia", "provas", "tabObras", "Prepress Ver Obras", numObra, "enviadaDia", "prova4")
	my sacarItensdaBasedeDadosTabView("env4hora", "provas", "tabObras", "Prepress Ver Obras", numObra, "enviadaHora", "prova4")
	
	my sacarItensdaBasedeDadosTabView("rec1dia", "provas", "tabObras", "Prepress Ver Obras", numObra, "recebidaDia", "prova1")
	my sacarItensdaBasedeDadosTabView("rec1hora", "provas", "tabObras", "Prepress Ver Obras", numObra, "recebidaHora", "prova1")
	
	my sacarItensdaBasedeDadosTabView("rec2dia", "provas", "tabObras", "Prepress Ver Obras", numObra, "recebidaDia", "prova2")
	my sacarItensdaBasedeDadosTabView("rec2hora", "provas", "tabObras", "Prepress Ver Obras", numObra, "recebidaHora", "prova2")
	
	my sacarItensdaBasedeDadosTabView("rec3dia", "provas", "tabObras", "Prepress Ver Obras", numObra, "recebidaDia", "prova3")
	my sacarItensdaBasedeDadosTabView("rec3hora", "provas", "tabObras", "Prepress Ver Obras", numObra, "recebidaHora", "prova3")
	
	my sacarItensdaBasedeDadosTabView("rec4dia", "provas", "tabObras", "Prepress Ver Obras", numObra, "recebidaDia", "prova4")
	my sacarItensdaBasedeDadosTabView("rec4hora", "provas", "tabObras", "Prepress Ver Obras", numObra, "recebidaHora", "prova4")
	
	my queProvasForamEnviadas("pdf1", "provas", "tabObras", "PrePress Ver Obras", numObra, "pdf", "prova1")
	my queProvasForamEnviadas("ozalide1", "provas", "tabObras", "PrePress Ver Obras", numObra, "ozalide", "prova1")
	my queProvasForamEnviadas("laser1", "provas", "tabObras", "PrePress Ver Obras", numObra, "laser", "prova1")
	my queProvasForamEnviadas("pcor1", "provas", "tabObras", "PrePress Ver Obras", numObra, "pdecor", "prova1")
	
	my queProvasForamEnviadas("pdf2", "provas", "tabObras", "PrePress Ver Obras", numObra, "pdf", "prova2")
	my queProvasForamEnviadas("ozalide2", "provas", "tabObras", "PrePress Ver Obras", numObra, "ozalide", "prova2")
	my queProvasForamEnviadas("laser2", "provas", "tabObras", "PrePress Ver Obras", numObra, "laser", "prova2")
	my queProvasForamEnviadas("pcor2", "provas", "tabObras", "PrePress Ver Obras", numObra, "pdecor", "prova2")
	
	my queProvasForamEnviadas("pdf3", "provas", "tabObras", "PrePress Ver Obras", numObra, "pdf", "prova3")
	my queProvasForamEnviadas("ozalide3", "provas", "tabObras", "PrePress Ver Obras", numObra, "ozalide", "prova3")
	my queProvasForamEnviadas("laser3", "provas", "tabObras", "PrePress Ver Obras", numObra, "laser", "prova3")
	my queProvasForamEnviadas("pcor3", "provas", "tabObras", "PrePress Ver Obras", numObra, "pdecor", "prova3")
	
	my queProvasForamEnviadas("pdf4", "provas", "tabObras", "PrePress Ver Obras", numObra, "pdf", "prova4")
	my queProvasForamEnviadas("ozalide4", "provas", "tabObras", "PrePress Ver Obras", numObra, "ozalide", "prova4")
	my queProvasForamEnviadas("laser4", "provas", "tabObras", "PrePress Ver Obras", numObra, "laser", "prova4")
	my queProvasForamEnviadas("pcor4", "provas", "tabObras", "PrePress Ver Obras", numObra, "pdecor", "prova4")
	
	-- Tab Impressão
	my sacarItensdaBasedeDadosTabView("maqImpressaoInterna", "impressao", "tabObras", "Prepress Ver Obras", numObra, "maqImpressaoInterna", "prepress")
	my sacarItensdaBasedeDadosTabView("lineatura", "impressao", "tabObras", "Prepress Ver Obras", numObra, "lineatura", "prepress")
	my sacarItensdaBasedeDadosTabView("tipoPapel", "impressao", "tabObras", "Prepress Ver Obras", numObra, "tipoPapel", "prepress")
	my sacarItensdaBasedeDadosTabView("impressaoExterna", "impressao", "tabObras", "Prepress Ver Obras", numObra, "impressaoExterna", "prepress")
	my sacarItensdaBasedeDadosTabView("coresCapa", "impressao", "tabObras", "Prepress Ver Obras", numObra, "coresCapa", "prepress")
	my sacarItensdaBasedeDadosTabView("pantoneCapa", "impressao", "tabObras", "Prepress Ver Obras", numObra, "pantoneCapa", "prepress")
	my sacarItensdaBasedeDadosTabView("coresMiolo", "impressao", "tabObras", "Prepress Ver Obras", numObra, "coresMiolo", "prepress")
	my sacarItensdaBasedeDadosTabView("pantoneMiolo", "impressao", "tabObras", "Prepress Ver Obras", numObra, "pantoneMiolo", "prepress")
	my sacarItensdaBasedeDadosTabView("obsCriarObra", "impressao", "tabObras", "Prepress Ver Obras", numObra, "obsCriarObra", "prepress")
	
	-- Tab Outros
	my introduzirImagem()
	my sacarItensdaBasedeDadosTabView("nomeComercial", "outros", "tabObras", "Prepress Ver Obras", numObra, "nomeComercial", "prepress")
	
	set contents of text field "procuraObras" of window "Prepress Ver Obras" to ""
end clicked






on sacarItensdaBasedeDados(textField, mainWindow, numObra, rowSQL, tabelaSQL)
	tell user defaults
		set theDatabaseFinal to contents of default entry "theDatabaseFinal"
	end tell
	
	set theDatabase to space & theDatabaseFinal & space
	set theDatabase to "sqlite3" & theDatabase & quote
	set numObra to space & "select " & rowSQL & " from " & tabelaSQL & " where nObra ='" & numObra & "'; "
	set nomeCliente to do shell script theDatabase & numObra & quote
	set contents of text field textField of window mainWindow to nomeCliente
	
end sacarItensdaBasedeDados

on sacarItensdaBasedeDadosTabView(textField, tabViewItem, tabView, mainWindow, numObra, rowSQL, tabelaSQL)
	tell user defaults
		set theDatabaseFinal to contents of default entry "theDatabaseFinal"
	end tell
	
	set theDatabase to space & theDatabaseFinal & space
	set theDatabase to "sqlite3" & theDatabase & quote
	set numObra to space & "select " & rowSQL & " from " & tabelaSQL & " where nObra ='" & numObra & "'; "
	set nomeCliente to do shell script theDatabase & numObra & quote
	set contents of text field textField of tab view item tabViewItem of tab view tabView of window mainWindow to nomeCliente
	
end sacarItensdaBasedeDadosTabView


on verificarEstadoDoTrabalho(popUp, mainWindow, numObra, rowSQL, tabelaSQL)
	
	tell user defaults
		set theDatabaseFinal to contents of default entry "theDatabaseFinal"
	end tell
	set theDatabase to space & theDatabaseFinal & space
	set theDatabase to "sqlite3" & theDatabase & quote
	set numObra to space & "select " & rowSQL & " from " & tabelaSQL & " where nObra ='" & numObra & "'; "
	set estado to do shell script theDatabase & numObra & quote
	
	if estado = "1" then
		set state of button popUp of window mainWindow to 1
	else
		set state of button popUp of window mainWindow to 0
	end if
end verificarEstadoDoTrabalho


on introduzirImagem()
	tell user defaults
		set theDatabaseFinal to contents of default entry "theDatabaseFinal"
	end tell
	try
		set nObra to get contents of text field "nObra" of window "Prepress Ver Obras"
		set theDatabase to space & theDatabaseFinal & space
		set theDatabase to "sqlite3" & theDatabase & quote
		set getImage to "select pathImagem from prepress where nObra='" & nObra & "';"
		set theImage to (do shell script theDatabase & getImage & quote)
		set theImage to theImage as alias
		set image of image view "previewImagem" of tab view item "outros" of tab view "tabObras" of window "PrePress Ver Obras" to load image theImage
	on error
		set image of image view "previewImagem" of tab view item "outros" of tab view "tabObras" of window "PrePress Ver Obras" to load image "nopreview.png"
	end try
end introduzirImagem

on queProvasForamEnviadas(theCheckBox, tabViewItem, tabView, mainWindow, numObra, rowSQL, tabelaSQL)
	tell user defaults
		set theDatabaseFinal to contents of default entry "theDatabaseFinal"
	end tell
	
	set theDatabase to space & theDatabaseFinal & space
	set theDatabase to "sqlite3" & theDatabase & quote
	set numObra to space & "select " & rowSQL & " from " & tabelaSQL & " where nObra ='" & numObra & "'; "
	set estado to do shell script theDatabase & numObra & quote
	
	if estado = "1" then
		set state of button theCheckBox of tab view item tabViewItem of tab view tabView of window mainWindow to 1
	else
		set state of button theCheckBox of tab view item tabViewItem of tab view tabView of window mainWindow to 0
	end if
	
	
end queProvasForamEnviadas